/*	This file is part of LSAC.

	LSAC is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	LSAC is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with LSAC.  If not, see <http://www.gnu.org/licenses/>.

	Copyright (c) 2010 LEPESME "Jiboo" Jean-Baptiste
*/

#include "cWhile.h"
#include "lsac.h"

cWhile::cWhile(cLocation pLocation, cBlock *pBlock, cExpression *pCondition)
	: cBlock(pLocation, pBlock)
{
	this->dCondition = pCondition;
}

cWhile::~cWhile()
{
	delete this->dCondition;
}

void cWhile::print(int pLevel)
{
	PRINT_LOG("cWhile " << this);
	PRINT_LOG("(");
	this->dCondition->print(pLevel + 1);
	PRINT_LOG(")");
	cBlock::print_statements(pLevel);
}

void cWhile::validate(cSemContext *pContext)
{
	this->dCondition->validate(pContext);
	if(this->dCondition->getType(pContext) != TYPE_BOOL) ERROR("Erreur en " << this->dLocation << " l' expression du 'tantque' doit etre de type 'booleen'");
	this->validate_statements(pContext);
}

void cWhile::genCode(ostream &pStream)
{
	pStream << "while(";
	this->dCondition->genCode(pStream);
	pStream << ")" << endl << "{" << endl;
	this->gen_statements(pStream);
	pStream << "}" << endl;
}
